# -*- Mode: Makefile;  -*-

## Set the configuration string used in filenames.
## `Make.rules' is the only Chombo makefile that uses this file, but
## it is separate so it can be used by non-Chombo code to construct
## the configuration string without using the rest of the Chombo
## makefile system.

## Usage:
##  When this file is `include'd in another makefile, the following
##  variables must already be defined:
##     CXX == name of the C++ compiler (or the name of the serial
##            C++ compiler used by the parallel C++ compiler)
##     MPICXX == name of the parallel C++ compiler
##     MPI == TRUE for parallel, FALSE for serial
##     OPENMPCC == TRUE for threading with OpenMP, FALSE without OpenMP
##     ROSE == TRUE for Rose compiler tranlations, FALSE otherwise
##     GPU == TRUE for Cuda code, FALSE otherwise
##     DEBUG == TRUE for symbol table, FALSE for no symbol table
##     OPT == FALSE no optimization
##            TRUE optimization, asserts, and initial setVal
##            HIGH optimization, no asserts, and initialize to zero
##     PRECISION == FLOAT or DOUBLE
##     DIM == 2 or 3, to specify the number of physical dimensions
##     system == operating system name
##     fc == name of Fortran compiler
##     USE_64 == {TRUE,FALSE} if TRUE, compile for 64bit pointers and add .64 to names
##     XTRACONFIG == user-defined configuration string
##     PIC == {TRUE,FALSE}      TRUE build position-independent code.
##
## Result: after `include'ing this file, the following are true:
##  the $(config) variable contains the full configuration string

makefiles+=Make.defs.config

# If OPT isn't set, set it to the opposite of DEBUG
ifeq ($(OPT),)
  ifeq ($(DEBUG),TRUE)
    OPT := FALSE
  endif
  ifeq ($(DEBUG),FALSE)
    OPT := TRUE
  endif
endif

# Set USE_SETVAL to TRUE unless OPT=HIGH
ifeq ($(USE_SETVAL),)
  USE_SETVAL := TRUE
  ifeq ($(OPT),HIGH)
    USE_SETVAL := FALSE
  endif
endif

# Disable memory tracking if OPENMPCC=TRUE as memory tracking is not thread safe
ifeq ($(OPENMPCC),TRUE)
  USE_MT=FALSE
endif

# First, set the compiler names.
# The C++ compiler depends on whether the compile is serial or parallel.
_cxxname := $(notdir $(firstword $(subst FALSE,$(CXX),$(subst TRUE,$(MPICXX),$(MPI)))))
_fname   := $(notdir $(firstword $(FC)))

# these variables specify pieces of the configuration string
_obj64     := $(subst FALSE,,$(subst TRUE,.64,$(USE_64)))
_precision := $(subst DOUBLE,,$(subst FLOAT,.FLOAT,$(PRECISION)))
_debug     := $(subst FALSE,,$(subst TRUE,.DEBUG,$(DEBUG)))
_opt       := $(subst FALSE,,$(subst TRUE,.OPT,$(subst HIGH,.OPTHIGH,$(OPT))))
_profile   := $(subst FALSE,,$(subst TRUE,.PROF,$(PROFILE)))
_mpi       := $(subst FALSE,,$(subst TRUE,.MPI,$(MPI)))
_petsc     := $(subst FALSE,,$(subst TRUE,.PETSC,$(USE_PETSC)))
_rose      := $(subst FALSE,,$(subst TRUE,.ROSE,$(ROSE)))
_gpu       := $(subst FALSE,,$(subst TRUE,.GPU,$(GPU)))
_ch        := $(subst FALSE,,$(subst TRUE,_ch,$(NAMESPACE)))
_md        := $(subst FALSE,,$(subst TRUE,md,$(MULTIDIM)))
_pic       := $(subst FALSE,,$(subst TRUE,.pic,$(PIC)))
_openmpcc  := $(subst FALSE,,$(subst TRUE,.OPENMPCC,$(OPENMPCC)))
_openmpfc  := $(subst FALSE,,$(subst TRUE,.OPENMPFC,$(OPENMPFC)))

# configuration string for multidim executable builds -- also use as a base
# for the other config strings

newconfig := $(shell echo                     $(system)$(_obj64).$(_cxxname).$(_fname)$(_precision)$(_debug)$(_opt)$(_profile)$(_mpi)$(_openmpcc)$(_openmpfc)$(_petsc)$(_rose)$(_gpu)$(_pic)$(XTRACONFIG) | sed -e 's/ //g' -e 's/	//g')

# create a base for all of the other config strings
baseconfig  := $(shell echo      d$(_ch)$(_md).$(system)$(_obj64).$(_cxxname).$(_fname)$(_precision)$(_debug)$(_opt)$(_profile)$(_mpi)$(_openmpcc)$(_openmpfc)$(_petsc)$(_rose)$(_gpu)$(_pic)$(XTRACONFIG) | sed -e 's/ //g' -e 's/	//g')

#these are config strings needed by multidim builds
1dconfig  := 1$(baseconfig)
2dconfig  := 2$(baseconfig)
3dconfig  := 3$(baseconfig)
4dconfig  := 4$(baseconfig)
5dconfig  := 5$(baseconfig)
6dconfig  := 6$(baseconfig)


# this is the one used by non-multidim builds
config    := $(shell echo $(DIM)$(baseconfig) | sed -e 's/ //g' -e 's/	//g')
